/*
 *  Copyright 2008-2010 www.jrails.org
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package org.rails.extjs.form;

import org.rails.extjs.Option;

public class TriggerField extends TextField {

	public TriggerField() {
		super();
	}

	public TriggerField(Option configOptions) {
		super(configOptions);
	}
	
	public TriggerField(String name) {
		super(name);
	}

	public TriggerField(String name, String fieldLabel) {
		super(name, fieldLabel);
	}

	public TriggerField(String name, String fieldLabel, Object value) {
		super(name, fieldLabel, value);
	}

	@Override
	public Tag getAutoCreate(){
		Tag ac = new Tag();
		ac.setTag("input");
		ac.setType("text");
		ac.setSize(16);
		ac.setAutocomplete("off");
		return getOption("autoCreate") == null ? ac : (Tag)getOption("autoCreate");
	}
	
	public void setEditable(Boolean editable){
		addOption("editable",editable);
	}
	
	public Boolean isEditable(){
		return getBoolean("editable",true);
	}
	
	public void setHideTrigger(Boolean hideTrigger){
		addOption("hideTrigger", hideTrigger);
	}
	
	public Boolean isHideTrigger(){
		return getBoolean("hideTrigger", false);
	}
	
	public void setTriggerClass(String triggerClass){
		addOption("triggerClass", triggerClass);
	}
	
	public String getTriggerClass(){
		return getString("triggerClass","x-form-trigger");
	}
	
	public void setWrapFocusClass(String wrapFocusClass){
		addOption("wrapFocusClass", wrapFocusClass);
	}
	
	public String getWrapFocusClass(String wrapFocusClass){
		return getString("wrapFocusClass","x-trigger-wrap-focus");
	}
	
	@Override
	public String getScript() {
		script = new StringBuffer("");
		createItems();
		script.append("new Ext.form.TriggerField(");
		script.append(createOptions());
		script.append(")");
		return script.toString();
	}
}
